package com.toplabs.unashu.controller;

import com.toplabs.unashu.annotation.ControllerEndpoint;
import com.toplabs.unashu.annotation.CurrentContent;
import com.toplabs.unashu.common.response.CommonResponse;
import com.toplabs.unashu.dto.ConfigDto;
import com.toplabs.unashu.entity.User;
import com.toplabs.unashu.service.ConfigService;
import com.toplabs.unashu.vo.ConfigVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * @author toplabs
 * @since 2022/11/21
 * <p>This java file was created by toplabs in 2022/11/21.
 * The following is the description information about this file:</p>
 * <p>description:</p>
 */
@Slf4j
@RestController
@RequestMapping("/config")
public class ConfigController {

    private final ConfigService configService;

    public ConfigController(ConfigService configService) {
        this.configService = configService;
    }

    @GetMapping("/detail/{id}")
    public CommonResponse<ConfigVO> getDetail(@PathVariable String id) {
        ConfigVO configVo = configService.getSysDetail(id);
        return CommonResponse.success(configVo);
    }

    @PutMapping("/update/{id}")
    @ControllerEndpoint(operation = "更新系统配置", exceptionMessage = "更新系统配置失败")
    public CommonResponse<String> update(@CurrentContent User user, @PathVariable("id") String id, @RequestBody ConfigDto configDto) {
        log.debug("config info: {}", configDto);
        configService.updateSysDetail(user, id, configDto);
        return CommonResponse.success("配置保存成功！");
    }
}
